/*
 * Copyright 2010 Gal Dolber.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jaspec;

import static junit.framework.Assert.*;

import java.util.Map;

/**
 * Map jaspec handler.
 */
public class JaspecMap<I, J> extends JaspecObject<Map<I, J>> {

  public JaspecMap(Map<I, J> obj) {
    super(obj);
  }

  public JaspecMap(Map<I, J> obj, boolean not) {
    super(obj, not);
  }

  /**
   * Check that the map have a number of...
   * 
   * @param n Number
   */
  public JaspecMapHave<I, J> have(int n) {
    return new JaspecMapHave<I, J>(this, n, Have.EXACTLY);
  }

  /**
   * Check that the map have at most a number of...
   * 
   * @param n Number
   */
  public JaspecMapHave<I, J> have_at_most(int n) {
    return new JaspecMapHave<I, J>(this, n, Have.AT_MOST);
  }

  /**
   * Check that the map have at least a number of...
   * 
   * @param n Number
   */
  public JaspecMapHave<I, J> have_at_least(int n) {
    return new JaspecMapHave<I, J>(this, n, Have.AT_LEAST);
  }

  /**
   * Check that the map include certain keys.
   * 
   * @param keys The keys
   */
  public void include_key(I... keys) {
    if (!not) {
      for (I i : keys) {
        assertTrue("The map should include the key " + i, obj.containsKey(i));
      }
    } else {
      for (I i : keys) {
        assertFalse("The map should not include the key " + i, obj.containsKey(i));
      }
    }
  }

  /**
   * Check that the map include certain values.
   * 
   * @param values The Values
   */
  public void include_value(J... values) {
    if (!not) {
      for (J i : values) {
        assertTrue("The map should include the value " + i, obj.containsValue(i));
      }
    } else {
      for (J i : values) {
        assertFalse("The map should not include the key " + i, obj.containsValue(i));
      }
    }
  }

  /**
   * Check that the map is empty.
   */
  public void be_empty() {
    boolean empty = obj.isEmpty();
    if (!not) {
      assertTrue("The map should be empty", empty);
    } else {
      assertFalse("The map should not be empty", empty);
    }
  }
}
